part of '../repository.dart';

const _kAdminUserRoleValue = 'admin';
const _kEndUserRoleValue = 'end_user';

class _UserRoleDto extends Equatable {
  const _UserRoleDto._internal({
    required this.roleString,
  });

  final String roleString;

  @override
  List<Object?> get props {
    return [
      roleString,
    ];
  }

  factory _UserRoleDto.fromString(String roleString) {
    return _UserRoleDto._internal(
      roleString: roleString,
    );
  }

  factory _UserRoleDto.fromEntity(UserRole role) {
    late final String roleString;

    if (role.isAdmin) {
      roleString = _kAdminUserRoleValue;
    } else if (role.isEndUser) {
      roleString = _kEndUserRoleValue;
    }

    return _UserRoleDto._internal(
      roleString: roleString,
    );
  }

  @override
  String toString() {
    return roleString;
  }

  UserRole toEntity() {
    if (roleString == _kAdminUserRoleValue) {
      return UserRole.admin;
    } else if (roleString == _kEndUserRoleValue) {
      return UserRole.endUser;
    }

    throw UnimplementedError();
  }
}
